package com.kolon.business.mngr.stat.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.business.mngr.service.dao.ServiceDao;
import com.kolon.business.mngr.stat.dao.StatDao;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;
import com.kolon.framework.util.PageUtil;

/**
 * 서비스 통계
 * @author stone
 */
@Controller("com.kolon.business.mngr.stat.controller.StatMonthDetailController")
public class StatMonthDetailController implements SimpleController {

	@Resource(name="com.kolon.business.mngr.stat.dao.StatDaoImpl")
	private StatDao statDao;
	@Resource(name="com.kolon.business.mngr.service.dao.ServiceDaoImpl")
	private ServiceDao serviceDao;
	
	@SuppressWarnings("rawtypes")
	@RequestMapping(value="/business/mngr/stat/statMonthDetail.do")
	public ModelAndView controller(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		Map<String, String> map = new HashMap<String, String>();
		// 파라미터
		int page = ComUtil.sToi(ComUtil.nullChk(request.getParameter("page"), "1"));
		String date = request.getParameter("date");
		String servNo = request.getParameter("servNo");
		map.put("servNo", servNo);
		map.put("date", date);
		int recordPerPage = 10;
		// 서비스 총 수
		int totCnt = statDao.getLogCount(map);
		// 페이지 네비게이터 생성
		PageUtil pageUtil = new PageUtil(
				page
			   ,request.getContextPath()
			   ,"/business/mngr/stat/statMonthDetail.do"
			   ,10
			   ,recordPerPage
			   ,totCnt
			   ,"&amp;servNo=" + servNo + 
			    "&amp;date=" + date);
		int startIndex = pageUtil.getRecordPerPage() * (page - 1);
		// 목록 조회
		List list = statDao.getLogPageList(map, startIndex, pageUtil.getRecordPerPage());
		// 리턴
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("servMap", serviceDao.getMap(map));
		modelAndView.addObject("totCnt", totCnt);
		modelAndView.addObject("list", list);
		modelAndView.addObject("page", page);
		modelAndView.addObject("pageHtml", pageUtil.getMakePage());
		modelAndView.addObject("pageCnt", pageUtil.getTotalNumOfPage());
		modelAndView.addObject("recordPerPage", recordPerPage);
		modelAndView.addObject("servNo", servNo);
		modelAndView.addObject("date", date);
		return modelAndView;
	}

}